package vikaa.adapter;

import java.util.ArrayList;

import vikaa.bean.Member_item;
import vikaa.tools.BitmapManager;
import vikaa.tools.HttpUtil;
import vikaa.tools.ValueClass;
import vikaa.wowo.R;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AdapterWowoMember extends BaseAdapter{
	private Context context;
	private LayoutInflater inflater;
	private final ArrayList<Member_item>  wbList; 
	 private BitmapManager 	bmpManager;
    
    public AdapterWowoMember(Context context, ArrayList<Member_item> wbList) {
		super();
		this.context = context;
		this.inflater = LayoutInflater.from(context);
		this.wbList = wbList;
		this.bmpManager = new BitmapManager(BitmapFactory.decodeResource(context.getResources(), R.drawable.widget_dface));
	}

    public int getCount() {
        return wbList.size();
    }

    public Object getItem(int position) {
        return wbList.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

	public View getView(int position, View convertView, ViewGroup parent) {
		Holder wh;
		Member_item wb = wbList.get(position);
		if(convertView == null){
			convertView = inflater.inflate(R.layout.wowo_member_list_item, null);
	        wh = new Holder();
	        wh.avater = (ImageView)convertView.findViewById(R.id.avater);
	        wh.nickname = (TextView)convertView.findViewById(R.id.nickname);
	        wh.text =(TextView)convertView.findViewById(R.id.text);
	        convertView.setTag(wh);
		}
		else{
			wh = (Holder)convertView.getTag();
		}
        wh.nickname.setText(wb.getScreen_name());
        if(wb.getProfile_image_url().length()<5){
        	wh.avater.setBackgroundResource(R.drawable.wowo_item_cover);
        }else{
        	//ImageUtil.loadCornerAvater(HttpUtil.HttpUrlComplete(wb.getProfile_image_url()), wh.avater,ValueClass.CORNER_PIXEL);
        	bmpManager.loadBitmap(HttpUtil.HttpUrlComplete(wb.getProfile_image_url()), wh.avater , true , ValueClass.CORNER_PIXEL);
        }
        wh.avater.setTag(wb);
        return convertView;
	}
	
	static class Holder {
    	public ImageView avater = null;
		public TextView nickname = null;
		public TextView text = null;
    }

}
